/*
 * trdp_mini_proto.h
 *
 *  Created on: 2016年12月26日
 *      Author: think
 */

#ifndef INC_TRDP_MINI_PROTO_H_
#define INC_TRDP_MINI_PROTO_H_

#include "../api/trdp_mini_types.h"

#ifdef __cplusplus
extern "C" {
#endif


/*  Default MD communication parameters   */
#define TRDP_MINI_MD_QOS				(2)
#define TRDP_MINI_MD_TTL				(100)
#define	TRDP_MINI_MD_INFINITE_TIME		(0xFFFFFFFF)

/*  Default PD communication parameters   */
#define	TRDP_MINI_PD_QOS				(3)
#define	TRDP_MINI_PD_TTL				(50)

/*  PD packet properties    */
#define	TRDP_MINI_MIN_PD_SIZE			(sizeof(TRDP_MINI_PD_HEAD_T))
#define	TRDP_MINI_MAX_PD_DATA_SIZE		(1460 - TRDP_MINI_MIN_PD_SIZE)
#define	TRDP_MINI_MAX_PD_SIZE			(1460)
#define	TRDP_MINI_MAX_MD_DATA_SIZE		(1460 - sizeof(TRDP_MINI_MD_HEADER_T))
#define	TRDP_MINI_MAX_MD_SIZE			(1460)

/* ------------------TYPEDEFS----------------------------------------------------  */
/** Message Types    */
typedef enum
{
    TRDP_MINI_MSG_PD = 0x5064,     /**< 'Pd' PD Data                                    */
	TRDP_MINI_MSG_PP = 0x5070,     /**< 'Pp' PD Data (Pull Reply)                       */
	TRDP_MINI_MSG_PR = 0x5072,     /**< 'Pr' PD Request                                 */
	TRDP_MINI_MSG_PE = 0x5065,     /**< 'Pe' PD Error                                   */
	TRDP_MINI_MSG_MN = 0x4D6E,     /**< 'Mn' MD Notification (Request without reply)    */
	TRDP_MINI_MSG_MR = 0x4D72,     /**< 'Mr' MD Request with reply                      */
	TRDP_MINI_MSG_MP = 0x4D70,     /**< 'Mp' MD Reply without confirmation              */
	TRDP_MINI_MSG_MQ = 0x4D71,     /**< 'Mq' MD Reply with confirmation                 */
	TRDP_MINI_MSG_MC = 0x4D63,     /**< 'Mc' MD Confirm                                 */
	TRDP_MINI_MSG_ME = 0x4D65      /**< 'Me' MD Error                                   */
} TRDP_MINI_MSG_T;

/** TRDP process data header - network order and alignment    */
typedef struct
{
    INT32U  sequenceCounter;                    /**< Unique counter (autom incremented)                     */
    INT16U  protocolVersion;                    /**< fix value for compatibility (set by the API)           */
    INT16U  msgType;                            /**< of datagram: PD Request (0x5072) or PD_MSG (0x5064)    */
    INT32U  comId;                              /**< set by user: unique id                                 */
    INT32U  etbTopoCnt;                         /**< set by user: ETB to use, '0' for consist local traffic */
    INT32U	localTopoCnt;						/* local topoCnt*/
    INT32U  datasetLength;                      /**< length of the data to transmit 0...1436                */
    INT32U  reserved;			   				/*according to DCEN											*/
    INT32U  replyComId;                         /**< used in PD request                                     */
    INT8U   replyIpAddress[4];                  /**< used for PD request                                    */
    INT32U  frameCheckSum;                      /**< CRC32 of header                                        */
} TRDP_MINI_PD_HEAD_T;

/** TRDP message data header - network order and alignment    */
typedef struct
{
    INT32U  sequenceCounter;                    /**< Unique counter (autom incremented)                     */
    INT16U  protocolVersion;                    /**< fix value for compatibility                            */
    INT16U  msgType;                            /**< of datagram: Mn, Mr, Mp, Mq, Mc or Me                  */
    INT32U  comId;                              /**< set by user: unique id                                 */
    INT32U  etbTopoCnt;                         /**< set by user: ETB to use, '0' for consist local traffic */
    INT32U	localTopoCnt;						/* local topoCnt*/
    INT32U  datasetLength;                      /**< defined by user: length of data to transmit            */
    INT32S  replyStatus;                        /**< 0 = OK                                                 */
    INT8U   sessionID[16];                      /**< UUID as a byte stream                                  */
    INT32U  replyTimeout;                       /**< in ms                                                  */
    INT8S   sourceURI[32];                      /**< User part of URI                                       */
    INT8S   destinationURI[32];                 /**< User part of URI                                       */
    INT32U  frameCheckSum;                      /**< CRC32 of header                                        */
} TRDP_MINI_MD_HEADER_T;

#ifdef __cplusplus
}
#endif

#endif /* INC_TRDP_MINI_PROTO_H_ */
